﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Linq;


namespace QuanLyKTX
{
    using Telerik.WinControls;
    using DAL;
    public partial class frm_ReportRoomBill : Telerik.WinControls.UI.RadForm
    {

        public string MaHoaDon { get; set; }

        public frm_ReportRoomBill()
        {
            InitializeComponent();
        }

        public frm_ReportRoomBill(string maHoaDon)
        {
            InitializeComponent();
            MaHoaDon = maHoaDon;
        }

        private void frm_ReportRoomBill_Load(object sender, EventArgs e)
        {
            using (var db = new QuanLyKTXDataContext())
            {
                var result = (from p in db.tbl_HoaDonPhongs
                              join q in db.tbl_HopDongs on p.MaHopDong equals q.MaHopDong
                              join s in db.tbl_SinhViens on q.ID equals s.ID
                              join k in db.tbl_Lops on s.MaLop equals k.MaLop
                              join t in db.tbl_Khoas on k.MaKhoa equals t.MaKhoa
                              join r in db.tbl_XepPhongs on q.ID equals r.ID
                              where p.MaHoaDon == new Guid(MaHoaDon)
                              select new
                              {
                                  p.MaHoaDon,
                                  p.MaHopDong,
                                  s.MaSinhVien,
                                  HoTen = s.Ho+" "+s.Ten,
                                  t.TenKhoa,
                                  k.MaLop,
                                  r.SoPhong,
                                  q.NgayBatDauHD,
                                  p.NgayThanhToan,
                                  p.SoTien
                              }).FirstOrDefault();
                                
                DataRow dr = dataSetHoaDonPhong.Tables[0].NewRow();
                dr["MaHoaDon"] = result.MaHoaDon.ToString();
                dr["MaHopDong"] = result.MaHopDong.ToString();
                dr["MaSinhVien"] = result.MaSinhVien.ToString();
                dr["HoTen"] = result.HoTen;
                dr["Khoa"] = result.TenKhoa;
                dr["Lop"] = result.MaLop;
                dr["SoPhong"] = result.SoPhong;
                dr["NgayBatDauHD"] = result.NgayBatDauHD;
                dr["NgayDongTien"] = result.NgayThanhToan;
                dr["SoTien"] = result.SoTien;

                dataSetHoaDonPhong.Tables[0].Rows.Add(dr);

                reportViewer_HoaDon.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("DataSet_HoaDonPhong", dataSetHoaDonPhong.Tables[0]));
                reportViewer_HoaDon.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout);
                reportViewer_HoaDon.ZoomMode = Microsoft.Reporting.WinForms.ZoomMode.PageWidth;
                this.reportViewer_HoaDon.RefreshReport();
            }
        }
    }
}
